package com.example.designpattenexample.memento.example;

import java.util.LinkedList;

public class VersionControlSystem {
    private LinkedList<Backup> backups = new LinkedList<>();
    private int nextVersion = 0 ;

    public void add(Backup backup){
        backup.setVersion(++nextVersion);
        this.backups.add(backup);
    }

    public Backup getVersion(int version){
        for (Backup backup : backups){
            if (backup.getVersion() == version)
                return backup;
        }
        return null;
    }

    public Backup getLastVersion(){
        return backups.getLast();
    }
}
